//CommRow.js  由行对象决定有多少行数 tr 还是放在这里 一行当中 确定有多少列
import React, {Component} from 'react';
import CommCell from './commCell';

import RowTableHead from './rowTableHead';
export default class CommRow extends Component {

    constructor(props) {
        super(props);
    this.state = {
        executeFormula:props.executeFormula
       };
    }
    handleClick=(e,rowNo,colNo)=> {
         this.props.handleCellSelect(e,rowNo,colNo);
    }

    handleCellDoubleClick=(e,rowNo,colNo)=> {
        this.props.handleCellDoubleClick(e,rowNo,colNo);
    }


    handleChangedCell=(rowNo,colNo,value)=>{
        this.props.handleChangedCell(rowNo,colNo,value);
}

    handleRowHeadMouseDown=(e,i)=> {
        this.props.handleRowHeadMouseDown(e,i);
    }

    getCommCell(rowNo,colNo,commDataVal,commValue,commIsThousandsFormat,commIsPercentageFormat,commDecimalPlace,cell_struct_model,
                commAlign,commborder_top,commborder_bottom,commborder_left,commborder_right,
                commaddFilter_bright,commcellBackgroundColor,commcell_font_cssArray,commCell_editing_mode) {
        return <CommCell
            rowNo={rowNo}
            colNo={colNo}
            commData={commDataVal}
            commValue={commValue}
            commIsThousandsFormat={commIsThousandsFormat}
            commIsPercentageFormat={commIsPercentageFormat}
            commDecimalPlace={commDecimalPlace}

            cell_struct_model={cell_struct_model}
            commAlign={commAlign}
            commborder_top={commborder_top}
            commborder_bottom={commborder_bottom}
            commborder_left={commborder_left}
            commborder_right={commborder_right}
            commaddFilter_bright={commaddFilter_bright}
            commcellBackgroundColor={commcellBackgroundColor}
            commcell_font_cssArray={commcell_font_cssArray}
            commCell_editing_mode={commCell_editing_mode}

            key={"CommCell"+rowNo+"_"+colNo}

            onClick={(e) => this.handleClick(e,rowNo,colNo)}
            onCellDoubleClick={(e) => this.handleCellDoubleClick(e,rowNo,colNo)}
            onChangedCell={(value)=> this.handleChangedCell(rowNo,colNo,value)}
            executeFormula={this.state.executeFormula}
        />
    }

    render() {

        let c = this.props.colNum;  //列数
        let rowNo = this.props.rowNo;  //行号
        let cells = [];


        //for (var j = 0; j < c; j++) {
        for (var j = 1; j < c; j++) {
            let commData=this.props.rowData[j]|| '';
            let commValue=this.props.rowValue[j]|| '';
            let cell_struct_model=this.props.row_struct_model[j];
            let commAlign=this.props.rowAligns[j]|| 1;
            let commIsThousandsFormat=this.props.rowIsThousandsFormat[j]|| 0;
            let commIsPercentageFormat=this.props.rowIsPercentageFormat[j]|| 0;
            let commDecimalPlace=this.props.rowDecimalPlace[j]|| 0;

            let commborder_top=this.props.rowborder_tops[j]|| '';
            let commborder_bottom=this.props.rowborder_bottoms[j]|| '';
            let commborder_left=this.props.rowborder_lefts[j]|| '';
            let commborder_right=this.props.rowborder_rights[j]|| '';
            let commaddFilter_bright=this.props.rowaddFilter_brights[j]|| '';
            let commcellBackgroundColor=this.props.rowcellBackgroundColors[j]|| '';
            let commcell_font_cssArray=this.props.rowcell_font_cssArray[j]|| '';
            let commCell_editing_mode=this.props.rowCell_editing_mode[j]|| '';
                cells.push(this.getCommCell(rowNo,j,
                    commData,commValue,commIsThousandsFormat,commIsPercentageFormat,commDecimalPlace,cell_struct_model,commAlign,commborder_top,commborder_bottom,commborder_left,commborder_right,
                    commaddFilter_bright,commcellBackgroundColor,commcell_font_cssArray,commCell_editing_mode));
        }
        console.log("=====cells=========");
        console.log(cells);
        return (
            <tr key={"rowNo_"+rowNo} className="ttr">
                <RowTableHead
                    rowNo={rowNo}
                    rowHeight={this.props.rowHeight}
                    handleRowHeadMouseDown={(e,rowNo)=>this.handleRowHeadMouseDown(e,rowNo)}
                />{cells}</tr>
        )
    }
}
